<template>
	<view class="profile-page">
		<view class="info yu-flex yu-between" style="padding: 40rpx;">
			<u-avatar size="180" mode="square" :src="userInfo.headimg?$api.json('baseUrl') +'/upload/'+ userInfo.headimg:'../../static/tab_profile.png'" @click="chooseimg"></u-avatar>
			<!-- <image :src="userInfo.headimg?$api.json('baseUrl') +'/upload/'+ userInfo.headimg:'../../static/tab_profile.png'" mode="aspectFit" style="width: 150rpx;height: 150rpx;border-radius: 50%;" @click="chooseimg"></image> -->
			<view class="name yu-flex-1" style="padding-left: 60rpx;">
				<view class="yu-font-19 yu-color-3 yu-bold"  v-if="userInfo.roleid==2">{{userInfo.employee.empname}}</view>
				<view class="yu-font-19 yu-color-3 yu-bold"  v-if="userInfo.roleid==1">{{userInfo.student.name}}</view>
				<view class="yu-pt-20">{{userInfo.phone}}</view>
			</view>
		</view>
		<view class="detial" v-if="userInfo.roleid==2">
			<u-cell-group>
				<u-cell-item title="性别" :value="userInfo.employee.empsex" :arrow="false">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/sex.png"></u-image>
					</view>
				</u-cell-item>
				<u-cell-item title="地址" :value="userInfo.employee.empaddress" :arrow="false">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/address.png"></u-image>
					</view>
				</u-cell-item>
			</u-cell-group>
			<u-cell-group>
				<u-cell-item title="毕业院校" :value="userInfo.employee.graduateschool" :arrow="false">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/school.png"></u-image>
					</view>
				</u-cell-item>
				<u-cell-item title="专业" :value="userInfo.employee.profession" :arrow="false">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/professional.png"></u-image>
					</view>
				</u-cell-item>
			</u-cell-group>
			<u-cell-group>
				<u-cell-item title="我的课程" :arrow="true" @click="gotoMyclass">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/singLog.png"></u-image>
					</view>
				</u-cell-item>
				<u-cell-item title="课程记录" :arrow="true" @click="gotoClassLog">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/singLog.png"></u-image>
					</view>
				</u-cell-item>
			</u-cell-group>
			<!-- <view class="ditem">接待人：{{userInfo.chargeperson}}</view>
			<view class="ditem">负责教师：{{userInfo.empname}}</view> -->
		</view>
		<view class="detial" v-if="userInfo.roleid==1">
			<u-cell-group>
				<u-cell-item title="性别" :value="userInfo.student.sex" :arrow="false">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/sex.png"></u-image>
					</view>
				</u-cell-item>
				<u-cell-item icon="account-fill" title="年龄" :value="userInfo.student.age" :arrow="false"></u-cell-item>
				<u-cell-item title="地址" :value="userInfo.student.address" :arrow="false">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/address.png"></u-image>
					</view>
				</u-cell-item>
			</u-cell-group>
			<u-cell-group>
				<u-cell-item title="我的课程" :arrow="true" @click="gotoMyclass">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/singLog.png"></u-image>
					</view>
				</u-cell-item>
				<u-cell-item title="课程记录" :arrow="true" @click="gotoClassLog">
					<view slot="icon" class="u-p-r-20">
						<u-image width="40" height="40" src="../../static/userimg/singLog.png"></u-image>
					</view>
				</u-cell-item>
			</u-cell-group>
			<u-cell-group>
				<u-cell-item icon="grid-fill" title="身份证号" :value="userInfo.student.idcard":arrow="false"></u-cell-item>
				<!-- <u-cell-item icon="grid-fill" title="获得证书" :value=" ":arrow="false"></u-cell-item> -->
			</u-cell-group>
			<u-cell-group>
				<u-cell-item icon="grid-fill" title="我的考级" :value="userKaoji.lessionname?userKaoji['lessionname'] + '-【'+userKaoji['level']+'级】-【'+passText[userKaoji['ispass']]+'】': '暂无考级'":arrow="false"></u-cell-item>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				passText: {
					'0':'待考核',
					'1':'通过',
					'2':'未通过'
				},
				wagesheight: '500',
				list: [],
				userInfo:{},
				userKaoji:{
					// lessionname:'测试',
					// level:'5',
					// ispass: 1
				},
				userObj: {},
				imgUrl:''
			}
		},
		onShow() {
			uni.getSystemInfo({
				success: (res) => {
					console.log(res);
					this.wagesheight = res.windowHeight
				}
			})
			this.getData()
		},
		methods: {
			lower() {
				
			},
			gotoMyclass(){
				uni.navigateTo({
					url:'/pages/myClass/myClass'
				})
			},
			gotoClassLog(){
				uni.navigateTo({
					url:'/pages/classLog/classLog'
				})
			},
			chooseimg(){
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album'], //从相册选择
				    success: (res)=> {
								console.log(res);
								uni.uploadFile({
									url: this.$api.json('baseUrl') + '/upload/fileUpload',
									file: res.tempFiles[0],
									filePath: res.tempFilePaths[0],
									name: 'files',
									fileType: 'image',
									success: (res) => {
										const ress = JSON.parse(res.data)
										console.log(ress.data, 88);
										this.imgUrl = ress.data
										this.uploadfile()
									}
								});
				    }
				});
			},
			uploadfile(){
				uni.showLoading({
				   title: '上传中...'
				});
				uni.request({
					method: 'POST',
					url: this.$api.json('baseUrl') + '/config/updateHeadimg',
					data: {
						headimg:this.imgUrl
					},
					success: (res) => {
						uni.showToast({
							title: res.data.resultInfo
						})
						if(res.data.resultCode=='000000'){
							this.getData()
						}
					}
				})
			},
			getKaoji(){
				uni.request({
					method: 'POST',
					url: this.$api.json('baseUrl') + '/kaoji/h5findKaojiList', 
					success: (res)=>{
						console.log(res, 444)
						if (res.data.resultCode==='000000') {
							if(res.data.data.length>0){
								this.userKaoji = res.data.data[0]
							}
						} else if(res.data.resultCode==='200009') {
							this.$api.msg('请先登录！');
							uni.redirectTo({
								url:'/pages/login/login'
							})
						} else {
							// this.$api.msg(res.data.resultInfo || '请求失败！');
						}
					},
				})
			},
			getData(){
				uni.showLoading({
				   title: '加载中'
				});
				uni.request({
					method: 'POST',
					url: this.$api.json('baseUrl') + '/student/h5findMyInfo',
					data: {
						stuid: 5
					},
					success: (res) => {
						setTimeout(e=>{uni.hideLoading()},100)
						if (res.data.resultCode==='000000') {
							this.userInfo = res.data.data
							this.getKaoji()
						} else if(res.data.resultCode==='200009') {
							this.$api.msg('请先登录！');
							uni.redirectTo({
								url:'/pages/login/login'
							})
						} else {
							this.$api.msg(res.data.resultInfo||'请求失败！');
						}
					}
				});
			},
			goTop: function(e) {
				uni.showToast({
					icon: "none",
					title: "纵向滚动 scrollTop 值已被修改为 0"
				})
			}
		}
	}
</script>

<style lang="less">
	.profile-page {
		.info {
			background-color: #fff;
		}
		.ditem{
			padding: 30rpx 20rpx;
			border-radius: 20rpx;
			background-color: #ffffff;
			border: 1px solid #F1F1F1;
			margin: 10rpx;
		}
	}
</style>
